Skip to content

Fix annotation default target warnings in enum constructors#602

Open
gioalex07 wants to merge 5 commits intoVREMSoftwareDevelopment:mainfrom
gioalex07:fix/annotation-default-target-param
Open

Fix annotation default target warnings in enum constructors#602
gioalex07 wants to merge 5 commits intoVREMSoftwareDevelopment:mainfrom
gioalex07:fix/annotation-default-target-param

Conversation

@gioalex07
Copy link
Copy Markdown

Summary

  • Add explicit @param: target to @StringRes, @DrawableRes and @ColorRes annotations on enum constructor parameters.
  • Resolves Kotlin compiler warning KT-73255 across 5 files.
  • No logic changes.

What does this implement/fix?

Kotlin 2.x introduced a warning when @StringRes, @DrawableRes or @ColorRes are applied to enum constructor
parameters without an explicit annotation target. In a future release, these annotations will be applied to both
the parameter and the backing field by default. This change opts in to the parameter-only behavior explicitly
using the @param: target, silencing the warning and future-proofing the code.

Affected files:

  • wifi/band/WiFiBand.kt@param:StringRes
  • wifi/model/Strength.kt@param:DrawableRes, @param:ColorRes
  • wifi/model/WiFiSecurity.kt@param:DrawableRes, @param:StringRes
  • wifi/model/WiFiStandard.kt@param:StringRes (x2)
  • wifi/model/WiFiWidth.kt@param:StringRes

Does this close any issues?

  • N/A (compiler warning cleanup)

How was this tested?

  • Platform: WSL2 / AlmaLinux 9
  • Build variant: debug
  • Toolchain: JDK 21 (Zulu), Gradle 9.3.1, Android SDK 36, Kotlin 2.3.0

gioalex07 and others added 2 commits April 2, 2026 18:33
Add explicit @param: target to @stringres, @DrawableRes and @ColorRes
annotations on enum constructor parameters to suppress KT-73255 warnings.
Kotlin 2.x will apply these annotations to both parameter and field by
default in a future release; this change opts in to the parameter-only
behavior explicitly.

Affected files: WiFiBand, Strength, WiFiSecurity, WiFiStandard, WiFiWidth
@VREMSoftwareDevelopment
Copy link
Copy Markdown
Owner

Thanks for the contribution.

  1. AI Usage Disclosure
    Disclose any AI tool involvement and use the “AI assistance used” label.

  2. Testing Requirements
    Changes must be tested on a real Android device.
    Emulator‑only testing or running build tasks (e.g., ktlintCheck, unit tests, successful Gradle build) is not sufficient.
    UI/UX behavior, layouts, gestures, and rendering often differ between emulators and actual devices.

Please update the PR with real‑device testing details so review can continue.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.83%. Comparing base (e3b385e) to head (c8548d5).

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #602   +/-   ##
=========================================
  Coverage     97.83%   97.83%           
  Complexity      975      975           
=========================================
  Files           121      121           
  Lines          2581     2581           
  Branches        211      211           
=========================================
  Hits           2525     2525           
  Misses           19       19           
  Partials         37       37           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@VREMSoftwareDevelopment VREMSoftwareDevelopment added the AI assistance used Indicates that an AI assistant was used to generate this PR label Apr 4, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates enum constructor resource annotations to silence Kotlin 2.x “default annotation target” warnings (KT-73255) by making the use-site target explicit.

Changes:

  • Add explicit @param: use-site targets for @StringRes, @DrawableRes, and @ColorRes on enum constructor val parameters.
  • Apply the change across 5 affected enums in wifi/band and wifi/model.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/WiFiWidth.kt Adds @param:StringRes to enum constructor textResource.
app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/WiFiStandard.kt Adds @param:StringRes to enum constructor fullResource / valueResource.
app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/WiFiSecurity.kt Adds @param:DrawableRes / @param:StringRes to enum constructor properties.
app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/Strength.kt Adds @param:DrawableRes / @param:ColorRes to enum constructor properties.
app/src/main/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiBand.kt Adds @param:StringRes to enum constructor textResource.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


enum class Security(
@DrawableRes val imageResource: Int,
@param:DrawableRes val imageResource: Int,
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param:DrawableRes will annotate only the constructor parameter; since imageResource is a val constructor property that’s read elsewhere, the property itself will no longer be annotated as @DrawableRes. If you rely on resource-type checking when using security.imageResource, consider using @get:/@field: (or both targets) instead of parameter-only.

Copilot uses AI. Check for mistakes.
enum class WiFiSecurityType(
val securityTypeId: SecurityTypeId,
@StringRes val textResource: Int,
@param:StringRes val textResource: Int,
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern here: @param:StringRes on a val constructor property annotates only the enum constructor parameter, not the textResource property that callers read later. If you want to keep WiFiSecurityType.textResource typed as @StringRes for lint/static checking, target the property (@get:/@field:) or apply both targets explicitly.

Suggested change
@param:StringRes val textResource: Int,
@param:StringRes @get:StringRes val textResource: Int,

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +26
@param:DrawableRes val imageResource: Int,
@param:ColorRes val colorResource: Int,
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param:DrawableRes / @param:ColorRes apply only to the enum constructor parameters. Since these are val constructor properties that are read later (e.g., strength.imageResource, strength.colorResource), this drops the resource annotations from the properties themselves and may reduce lint/resource-type checking at call sites. Consider targeting the property (@get:/@field:) or explicitly applying both targets.

Suggested change
@param:DrawableRes val imageResource: Int,
@param:ColorRes val colorResource: Int,
@param:DrawableRes @get:DrawableRes val imageResource: Int,
@param:ColorRes @get:ColorRes val colorResource: Int,

Copilot uses AI. Check for mistakes.

enum class WiFiBand(
@StringRes val textResource: Int,
@param:StringRes val textResource: Int,
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param:StringRes applies the annotation only to the constructor parameter; since this is a val constructor property, the generated textResource property/getter will no longer be annotated as a @StringRes. If this value is read elsewhere (e.g., passed into getString(...)), you likely want the annotation on the property as well (use @get:StringRes or @field:StringRes, or add both use-site targets explicitly).

Suggested change
@param:StringRes val textResource: Int,
@get:StringRes val textResource: Int,

Copilot uses AI. Check for mistakes.

enum class WiFiWidth(
@StringRes val textResource: Int,
@param:StringRes val textResource: Int,
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using @param:StringRes on a val constructor property means only the constructor parameter is annotated; the textResource property itself won’t carry @StringRes anymore. If callers read wiFiWidth.textResource and pass it to APIs expecting a @StringRes, consider targeting the property (@get:/@field:) or applying both targets explicitly to preserve resource-type safety while silencing KT-73255.

Suggested change
@param:StringRes val textResource: Int,
@param:StringRes @get:StringRes val textResource: Int,

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +32
@param:StringRes val fullResource: Int,
@param:StringRes val valueResource: Int,
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param:StringRes targets only the constructor parameter. Because fullResource/valueResource are val constructor properties that are accessed elsewhere, this change drops the @StringRes annotation from the property/getter/field, which may reduce lint/resource-type checking at call sites. Consider @get:/@field: (or duplicating targets) so the enum properties remain annotated.

Suggested change
@param:StringRes val fullResource: Int,
@param:StringRes val valueResource: Int,
@get:StringRes val fullResource: Int,
@get:StringRes val valueResource: Int,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

@VREMSoftwareDevelopment VREMSoftwareDevelopment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change — quick consistency suggestion based on the Copilot review noise (some suggestions were inconsistent).

Recommendation:

  1. Public constructor properties: annotate both parameter and getter so we get constructor-site and consumer-side checks: Example (from WiFiBand.kt): @get:StringRes @param:StringRes val textResource: Int
  2. Private constructor properties: annotate only the parameter: @param:LayoutRes private val layout: Int

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI assistance used Indicates that an AI assistant was used to generate this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants